<template>
  <!-- 平台财务  财务流水 -->
  <div class="app-container " v-loading="loading">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      class="search-form-new"
      label-width="auto"
      @keyup.enter.native="getList"
    >
      <el-form-item label="店铺" prop="tenantId" v-hasPermi="['searchTenantID']">
        <el-select v-model="queryParams.tenantId" placeholder="请选择店铺" clearable filterable>
          <el-option v-for="dict in tenantList" :key="dict.tenantId" :label="dict.tenantName" :value="dict.tenantId" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select
          v-model="queryParams.orderType"
          placeholder="请选择订单类型"
          size="small"
          clearable
        >
          <el-option
            v-for="(dict, key) in commonMaps.billOrderTypeMap"
            :key="key"
            :label="dict"
            :value="key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="账单类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择账单类型"
          size="small"
          clearable
        >
          <el-option
            v-for="(dict, key) in commonMaps.billTypeMap"
            :key="key"
            :label="dict.label"
            :value="key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易方名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入交易方名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="日期" prop="remark">
        <el-date-picker
          v-model="timer"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="searchList"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item class="btns">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="searchList"
          class="zdy-btn"
          >搜索</el-button
        >
        <el-button
          icon="el-icon-refresh"
          type="primary"
          plain
          size="mini"
          @click="resetQuery"
          class="zdy-btn zdy-btn-refresh"
          >重置</el-button
        >
        <!-- <el-button
          icon="el-icon-refresh"
          type="primary"
          plain
          size="mini"
          @click="systemBill"
          class="zdy-btn zdy-btn-refresh"
          >余额流水</el-button
        > -->
      </el-form-item>
    </el-form>
    <!--总计 -->
    <div style="margin: 10px;font-size: 16px;">
      <span>
        收入总计： <span style="font-size: 20px;color: yellowgreen;">{{ totalNum.shouru||0 }}</span>
      </span>
      <span style="margin: 0 20px;">
        支出总计： <span style="font-size: 20px;color: red;">{{ totalNum.zhichu||0 }}</span>
      </span>
      <span>
        服务费总计： <span style="font-size: 20px;color: #6C5DD3;">{{ totalNum.fuwufei||0 }}</span>
      </span>
      
    </div>
    <div class="table_box">
      <el-table
        :data="tableData.records"
        stripe
        border
        style="width: 100%"
      >
        <!-- <el-table-column
          prop=""
          label="归属部门"
          min-width="120"
        ></el-table-column> -->
        <el-table-column
          prop="id"
          label="ID"
          width="55"
        ></el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          min-width="120"
        ></el-table-column>
        <el-table-column prop="orderType" label="订单类型" >
          <template slot-scope="scope">
            <div>
              {{ commonMaps.billOrderTypeMap[scope.row.orderType] }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="orderNo"
          label="来源单号"
          min-width="160"
          
        ></el-table-column>
        <!-- <el-table-column
          prop="no"
          label="账单编号"
          min-width="120"
        ></el-table-column> -->
        <el-table-column prop="type" label="账单类型" >
          <template slot-scope="scope">
            <div>
              {{ commonMaps.billTypeMap[scope.row.type].label }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="amount"
          label="金额"
        ></el-table-column>
        <el-table-column
          prop="tenantName"
          label="店铺"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="userName"
          label="用户"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="operatorName"
          label="处理人"
        ></el-table-column>
        <el-table-column
          prop="serviceAmount"
          label="平台服务费"
        ></el-table-column>
        <!-- <el-table-column prop="state" label="状态" width="120">
          <template slot-scope="scope">
            <div>
              {{ commonMaps.billStatusMap[scope.row.state] }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="img" label="附件" >
          <template slot-scope="scope">
            <div class="link" @click="viewImgs(scope.row)">查看附件</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
          min-width="120"
        ></el-table-column>
      </el-table>
    </div>
    <div class="pages-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 40, 50, 60]"
        :page-size="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.total"
      ></el-pagination>
    </div>
    <!-- <orderDetailDialog ref="orderDetailDialog"></orderDetailDialog> -->
    <imageDialog ref="imageDialog"></imageDialog>
  </div>
</template>

<script>
// import orderDetailDialog from "../businessCenter/saleOrder/components/orderDetailDialog";
import billListApi from "@/api/financeCenter/billList.js";
import imageDialog from '@/components/imageDialog.vue'
export default {
  name: "bullList",
  components: {
    // orderDetailDialog,
    imageDialog
  },
  data() {
    return {
      timer: [],
      // 提号时间，商品ID 游戏类型 区服 实名状态   游戏账号【对应的商品链接】
      tableData: {
        records: [],
        total: 0,
      },
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        operatorTimeStart: "",
        operatorTimeEnd: "",
        state:1,
        tenantId:''
      },
      totalNum:{

      }
    };
  },
  created() {
    this.getList();
  },
  activated() {},
  computed: {
    tenantList() {
      return this.$store.getters.tenantList;
    },
  },
  methods: {
    // 获取列表
    getList() {
      // queryParams 请求列表
      this.loading = true;
      this.totalNum ={}
      if (this.timer && this.timer.length == 2) {
        this.queryParams.operatorTimeStart = this.timer[0] + " 00:00:00";
        this.queryParams.operatorTimeEnd = this.timer[1] + " 23:59:59";
      } else {
        this.queryParams.operatorTimeStart = "";
        this.queryParams.operatorTimeEnd = "";
      }
      billListApi.getList(this.queryParams).then((res) => {
        this.loading = false;
        this.tableData.records = res.rows;
        this.tableData.total = res.total;
        this.totalNum = {...res.params}
      });
    },
    // 搜索
    searchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 打开查看图片弹窗
    viewImgs(row) {
      let arr = []
      if (row.img) {
        let list = JSON.parse(row.img)
        if (list.length) {
          list.forEach(element => {
            arr.push(element.url)
          });
        } else {
          return this.$alert('暂无图片')
        }
      } else {
        return this.$alert('暂无图片')
      }
      this.$refs.imageDialog.open(arr)
    },

    //查看订单详情
    goOrderDetail(id) {
      this.$refs.orderDetailDialog.open(id, "kefu");
    },
    // 余额账单
    systemBill(){
      this.timer = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 20,
        operatorTimeStart: "",
        operatorTimeEnd: "",
        state:3
      };
      this.getList();
    },

    resetQuery() {
      this.timer = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 20,
        operatorTimeStart: "",
        operatorTimeEnd: "",
        state:1,
        tenantId:''
      };
      this.getList();
    },

    // 每页条数改变
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    // 页码改变
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    exportOrder() {},
  },
};
</script>
<style lang="scss" scoped>
.link {
  color: blue;
  cursor: pointer;
}
</style>
